﻿Imports System.Data.SqlClient
Public Class frmEmployee
    Public Sub RefreshData()
        DataGridView1.DataSource = cmd.ExecuteReader("select  * from tblemployee where emp_name like '%" & cboEm_name.Text & "%'")
    End Sub
    Private Sub frmEmployee_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        RefreshData()
    End Sub

    Private Sub btndelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndelete.Click
        If DataGridView1.SelectedRows.Count = 0 Then
            MsgBox("Please selected 1 row first!")
            Exit Sub
        End If

        If MessageBox.Show("Are you sure want to delete this row?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.No Then
            Exit Sub
        End If

        Dim row = DataGridView1.SelectedRows(0)
        Dim code = row.Cells(0).Value

        cmd.ExecuteNonQuery("DELETE FROM tblemployee WHERE emp_id='" & code & "'")

        RefreshData()

    End Sub

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click

        frmEmployeeEditter.ShowDialog()
    End Sub

    Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
        If DataGridView1.SelectedRows.Count = 0 Then
            MsgBox("Please selected 1 row first!")
        End If
        Dim row = DataGridView1.SelectedRows(0)
        Dim code = row.Cells(0).Value

    End Sub

    Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click
        frmEmployeeEditter.ShowDialog()
    End Sub
End Class
